package controller

import (
	"gicechina/help"
	"net/http"
	"gicechina/model"
)

var TemplateData map[string]interface{}
var NewsModel = new(model.News)
var CategoryModel = new(model.Category)
var ActiveModel = new(model.Active)
var JobModel = new(model.Job)

func init()  {
	TemplateData = make(map[string]interface{})
	TemplateData["indexCurrent"] = "current"
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
}
type IndexController struct{}

func (c *IndexController) Index(w http.ResponseWriter, r *http.Request) {
	TemplateData["indexCurrent"] = "current"
	TemplateData["aboutCurrent"] = ""
	TemplateData["activeCurrent"] = ""
	TemplateData["projectCurrent"] = ""
	TemplateData["videoCurrent"] = ""
	TemplateData["newsCurrent"] = ""
	TemplateData["contactCurrent"] = ""
	TemplateData["jobCurrent"] = ""
	//获得gice项目
	getGiceProject()
	//获得gice活动
	getGiceActive()
	getGiceProject()
	getGiceVideo()
	help.ParseTemplate(w, "index.html", &TemplateData, "layout","index","header", "footer")
}

//获得GICE项目
func getGiceProject() {
	params := make(map[string]interface{})
	params["category_id"] = "3"
	params["status"] = "2"
	params["sort"] = "update_time desc"
	params["limit"] = "4"
	projects := NewsModel.Item(params)
	TemplateData["projects"] = projects
	projectInfo,_ := CategoryModel.GetInfoById(3)
	TemplateData["projectInfo"] = projectInfo
}
//获得GICE活动
func getGiceActive() {
	params := make(map[string]interface{})
	params["category_id"] = "2"
	params["status"] = "2"
	params["sort"] = "update_time desc"
	params["limit"] = "4"
	projects := ActiveModel.Item(params)
	TemplateData["actives"] = projects
	projectInfo,_ := CategoryModel.GetInfoById(2)
	TemplateData["activeInfo"] = projectInfo
}
//获得GICE报道
func getGiceReport() {
	params := make(map[string]interface{})
	params["category_id"] = "5"
	params["status"] = "2"
	params["sort"] = "update_time desc"
	params["limit"] = "4"
	projects := NewsModel.Item(params)
	TemplateData["reports"] = projects
	projectInfo,_ := CategoryModel.GetInfoById(5)
	TemplateData["reportInfo"] = projectInfo
}
//获得GICE在线视屏
func getGiceVideo() {
	params := make(map[string]interface{})
	params["category_id"] = "4"
	params["status"] = "2"
	params["sort"] = "update_time desc"
	params["limit"] = "3"
	projects := NewsModel.Item(params)
	TemplateData["index_videos"] = projects
	projectInfo,_ := CategoryModel.GetInfoById(4)
	TemplateData["videoInfo"] = projectInfo
}